<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				设备维修
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="top clearfix">
				<view class="left fl clearfix">
					<view class="mess fl">
						<view :class="[attrIndex==1?'active':'']" @click="attrIndex = 1">充电宝损坏</view>
						<text class="dian" v-if="attrIndex == 1"></text>
					</view>
					<view class="mess mess1 fl" @click="attrIndex = 2">
						<view :class="[attrIndex==2?'active':'']">机柜损坏</view>
						<text class="dian" v-if="attrIndex == 2"></text>
					</view>
				</view>
			</view>
		</view>
		<view v-if="attrIndex == 1">
			<view class="form">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请输入设备SN<text>*</text></view>
				</view>
				<view class="content contentlast clearfix">
					<view class="name fl">设备SN码</view>
					<view class="inp fr">
						<input type="text" v-model="formData.sn" placeholder="请输入充电宝编码" />
					</view>
				</view>
			</view>
			
			
			<view class="form form1" @click="chooseImage" v-if="formData.sitepicture==''">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请添加设备图片<text>*</text><text>请上传充电宝对应的SN码图片</text></view>
				</view>
				<view class="content contenttp contentlast clearfix">
					<image :src="baseUrl + '/wximage/add.png'" class="shangchuan"></image>
				</view>
			</view>
			
			
			<view class="form form1" v-else @click="chooseImage">
				<view class="content contentdx contentlast clearfix" >
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<!-- <view class="name fl">请添加设备图片<text>*</text><text>请上传充电宝对应的SN码图片</text></view> -->
				</view>
				<view class="content contenttp contentlast clearfix">
					<image :src="formData.sitepicture"  class="shangchuan"></image>
				</view>
			</view>
			
			
			<view class="form form1">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请选择维修原因<text>*</text></view>
				</view>
				<view class="content clearfix" @click="formData.cause=1">
					<view class="name fl">不能充电</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==1"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content clearfix" @click="formData.cause=2">
					<view class="name fl">数据线头摔坏</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==2"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content clearfix" @click="formData.cause=3">
					<view class="name fl">鼓包</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==3"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content clearfix" @click="formData.cause=4">
					<view class="name fl">归还无法失败</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==4"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content contentlast clearfix" @click="formData.cause=5">
					<view class="name fl">其他原因</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==5"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
			</view>
			<view class="form form1">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">收货地址<text>*</text><text>(请输入设备维修后的收货信息)</text></view>
				</view>
				<view class="content clearfix">
					<view class="name fl">收件人</view>
					<view class="inp fr">
						<input type="text" v-model="formData.addressee" placeholder="请输入收件人姓名" />
					</view>
				</view>
				<view class="content clearfix">
					<view class="name fl">联系方式</view>
					<view class="inp fr">
						<input type="text" v-model="formData.mobile" placeholder="请输入联系方式" />
					</view>
				</view>
				<view class="content contentlast clearfix">
					<view class="name fl">收件地址</view>
					<view class="inp fr">
						<input type="text" v-model="formData.address" placeholder="请输入收件地址" />
					</view>
				</view>
			</view>
		</view>
		<view v-if="attrIndex == 2">
			<view class="form">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请输入设备SN<text>*</text></view>
				</view>
				<view class="content contentlast clearfix">
					<view class="name fl">设备SN码</view>
					<view class="inp fr">
						<input type="text" v-model="formData.sn" placeholder="请输入机柜编码" />
					</view>
				</view>
			</view>
			
			
			
			<!-- <view class="form form1">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请添加设备图片<text>*</text><text>请上传机柜对应的SN码图片</text></view>
				</view>
				<view class="content contenttp contentlast clearfix">
					<image :src="baseUrl + '/wximage/add.png'" class="shangchuan"></image>
				</view>
			</view> -->
			
			<view class="form form1" v-if="formData.sitepicture==''" @click="chooseImage">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请添加设备图片<text>*</text><text>请上传机柜对应的SN码图片</text></view>
				</view>
				<view class="content contenttp contentlast clearfix">
					<image :src="baseUrl + '/wximage/add.png'" class="shangchuan"></image>
				</view>
			</view>
			
			<view class="form form1" v-else @click="chooseImage">
				<view class="content contentdx contentlast clearfix" >
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<!-- <view class="name fl">请添加设备图片<text>*</text><text>请上传机柜对应的SN码图片</text></view> -->
				</view>
				<view class="content contenttp contentlast clearfix">
					<image :src="formData.sitepicture" class="shangchuan"></image>
				</view>
			</view>
			
			
			<view class="form form1">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">请选择维修原因<text>*</text></view>
				</view>
				<view class="content clearfix" @click="formData.cause=6">
					<view class="name fl">仓口无法识别</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==6"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content clearfix" @click="formData.cause=7">
					<view class="name fl">无法通电(离线)</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==7"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content clearfix" @click="formData.cause=8">
					<view class="name fl">叠加层叠加无反应</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==8"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
				<view class="content contentlast clearfix" @click="formData.cause=9">
					<view class="name fl">其他原因</view>
					<view class="inp fr">
						<image :src="baseUrl + '/wximage/yixz.png'" v-if="formData.cause==9"></image>
						<image :src="baseUrl + '/wximage/weixz.png'" v-else></image>
					</view>
				</view>
			</view>
			<view class="form form1">
				<view class="content contentdx contentlast clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="danxuan fl"></image>
					<view class="name fl">收货地址<text>*</text><text>(请输入设备维修后的收货信息)</text></view>
				</view>
				<view class="content clearfix">
					<view class="name fl">收件人</view>
					<view class="inp fr">
						<input type="text" v-model="formData.addressee" placeholder="请输入收件人姓名" />
					</view>
				</view>
				<view class="content clearfix">
					<view class="name fl">联系方式</view>
					<view class="inp fr">
						<input type="text" v-model="formData.mobile" placeholder="请输入联系方式" />
					</view>
				</view>
				<view class="content contentlast clearfix">
					<view class="name fl">收件地址</view>
					<view class="inp fr">
						<input type="text" v-model="formData.address" placeholder="请输入收件地址" />
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="submit" @click="submit">提交申请</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				attrIndex: 1,
				formData:{
					sn: '',
					user_id:uni.getStorageSync('agent_id'),
					sitepicture: '',
					cause: '',
					addressee: '',
					mobile: '',
					address: '',
					type:1
				}
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		methods: {
			chooseImage() {
				let that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
					success: function(res) {
						uni.uploadFile({
							url: 'https://aapi.jixiaodian.cn/api/common/cosupdate',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: function(res1) {
								let arr = JSON.parse(res1.data);
								that.formData.sitepicture = arr.data.path;
							},
							fail: function(res1) {
			
							},
						})
					}
				})
			},
			submit(){
				//提交维修记录
				this.request({
					url: '/wxdevice/devicerepair',
					data: this.formData,
					method: "POST"
				}).then(res1 => {
					if (res1.data.code == 200) {
						
						setTimeout(function() {
							uni.showToast({
								title: '申请成功',
								icon: 'none'
							})
							uni.redirectTo({
								url: '/subpackageA/equipment/index'
							})
						}, 500);
						
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
				
				
				// uni.redirectTo({
				// 	url: '/subpackageA/merchant/divide'
				// })
			},
			confirmlx(e) {
				this.lxvalue = e[0].value;
				this.lxlabel = e[0].label;
				
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;
					
			.top{
				.left {
					.mess {
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;
			
						view {
							font-size: 24rpx;
							color: #333333;
						}
			
						.dian {
							width: 8rpx;
							height: 8rpx;
							background: #5C88FA;
							display: block;
							border-radius: 50%;
							margin: 0 auto;
						}
			
						.active {
							font-size: 32rpx;
							color: #333333;
							font-weight: 700;
							margin-left: 0;
						}
					}
			
					.mess1 {
						margin-left: 20rpx;
					}
				}
			
				.right {
					width: 124rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 6rpx;
			
					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}
		
		.form{
			width: 94%;
			margin: 0 auto;
			margin-top: -200rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 20rpx;
			box-shadow:rgba(223, 230, 255, 0.67) 0px 0px 6px;
			
			.content{
				height: 92rpx;
				line-height: 92rpx;
				border-bottom: 1rpx solid #D8D8D8;
				
				.name{
					font-size: 28rpx;
					color: #333333;
					width: 40%;
					
					text:nth-of-type(1){
						color: #FA5E5C;
					}
					
					text:nth-of-type(2){
						font-size: 24rpx;
						color: #999999;
					}
				}
				
				.inp{
					width: 60%;
					text-align: right;
					height: 92rpx;
					line-height: 92rpx;
					
					input{
						font-size: 28rpx;
						color: #999999;
						height: 92rpx;
						line-height: 92rpx;
					}
					
					image{
						width: 50rpx;
						height: 50rpx;
						margin-top: 18rpx;
					}
				}
				
				.xuanze{
					width: 60%;
					text-align: right;
					height: 92rpx;
					line-height: 92rpx;
					color: #368BF8;
				}
				
				.shangchuan{
					width: 100rpx;
					height: 100rpx;
					margin-left: 74rpx;
				}
			}
			
			.contentlast{
				border: none;
			}
			
			.contenttp{
				height: 120rpx;
			}
			
			.contentdx{
				
				.name{
					font-size: 28rpx;
					color: #333333;
					width: 90%;
				}
				
				image{
					width: 40rpx;
					height: 40rpx;
					margin-top: 26rpx;
				}
				
				.inp{
					width: 40%;
				}
				
				.xuanze{
					width: 80%;
				}
			}
		}
		
		.form1{
			margin-top: 20rpx;
		}
		
		.footer{
			width: 100%;
			margin: 0 auto 40rpx;
			margin-top: 60rpx;
			height: 72rpx;
			text-align: center;
			
			.submit{
				width: 240rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: linear-gradient(90deg, #65bdfc, #398ef8);
				margin-left: 248rpx;
				border-radius: 36rpx;
				border-top-left-radius: 0;
				border-bottom-left-radius: 42rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>